<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:11pt; font-weight:400; font-style:normal;">
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" width="100%" cellspacing="5" cellpadding="0">
<tr>
<td style=" vertical-align:middle;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a name="ctl10_ctl03_PanelHeader"></a><span style=" font-family:'DejaVu Sans'; color:#c91f49;">О</span><span style=" font-family:'DejaVu Sans'; color:#c91f49;">тправить письмо из Outlook                                                        </span><span style=" font-family:'DejaVu Sans';">        </span><span style=" font-family:'DejaVu Sans';">        </span></p></td>
<td rowspan="3" style=" vertical-align:top; padding-left:10; padding-right:10; padding-top:10; padding-bottom:10;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';">            </span><a name="ctl10_ctl03_ImageLogo"></a><span style=" font-family:'DejaVu Sans';"> </span><span style=" font-family:'DejaVu Sans';">                   </span><span style=" font-family:'DejaVu Sans';">        </span></p></td></tr>
<tr>
<td style=" vertical-align:top;">
<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-family:'DejaVu Sans';" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">	                             </li></ul></td></tr>
<tr>
<td style=" vertical-align:top; padding-left:15; padding-right:15; padding-top:15; padding-bottom:15;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';">            </span><a name="ctl10_ctl03_ProductDescription"></a><span style=" font-family:'DejaVu Sans';">0</span><span style=" font-family:'DejaVu Sans';">1. Этот пример (1) позволяет вам отправить электронное сообщение из Access через Outlook. Для работы программы в новых файлах создайте ссылку на Outlook в VBA: C:\Program Files\Microsoft Office\OFFICE11\MSOUTL.OLB</span><span style=" font-family:'DejaVu Sans';">        </span><span style=" font-family:'DejaVu Sans';">        </span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVu Sans';"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'==============================================================</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'  Назначение</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'    &quot;Послать почту из базы данных&quot;</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Private Sub </span><span style=" font-family:'Courier New'; font-size:small;">butExecute_Click()<br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">app </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As </span><span style=" font-family:'Courier New'; font-size:small;">Outlook.Application  </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Приложение программы</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">dbs </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As </span><span style=" font-family:'Courier New'; font-size:small;">Database </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'База данных</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">rst </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As </span><span style=" font-family:'Courier New'; font-size:small;">Recordset </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Источник email</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">i </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As Integer </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Счетчик</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">itm </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As </span><span style=" font-family:'Courier New'; font-size:small;">MailItem </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Почтовое сообщение</span><span style=" font-family:'Courier New'; font-size:small;"><br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">myFile </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As String </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Присоединяемый файл</span><span style=" font-family:'Courier New'; font-size:small;"><br /><br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">On Error GoTo </span><span style=" font-family:'Courier New'; font-size:small;">999<br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">dbs = CurrentDb </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Выбор базы данных</span><span style=" font-family:'Courier New'; font-size:small;"><br />    Me.Refresh </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Сохраняем данные</span><span style=" font-family:'Courier New'; font-size:small;"><br />    myFile = Application.CurrentProject.Path &amp; </span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;\&quot;</span><span style=" font-family:'Courier New'; font-size:small;"> &amp; Me.Attachment<br />    myFile = Dir(myFile)<br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Открываем таблицу c почтовыми адресами</span><span style=" font-family:'Courier New'; font-size:small;"><br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">rst = dbs.OpenRecordset(</span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;SELECT * FROM [Пример 01email] WHERE ([Вкл]=True);&quot;</span><span style=" font-family:'Courier New'; font-size:small;">)<br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">If </span><span style=" font-family:'Courier New'; font-size:small;">rst.RecordCount &lt;&gt; 0 </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Then </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Проверяем записи</span><span style=" font-family:'Courier New'; font-size:small;"><br />        rst.MoveLast </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Заполняем запрос</span><span style=" font-family:'Courier New'; font-size:small;"><br />        rst.MoveFirst </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Первая запись</span><span style=" font-family:'Courier New'; font-size:small;"><br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">app = </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">New </span><span style=" font-family:'Courier New'; font-size:small;">Outlook.Application </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Новое сообщение</span><span style=" font-family:'Courier New'; font-size:small;"><br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Dim </span><span style=" font-family:'Courier New'; font-size:small;">myNamespace, myfolder </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">As </span><span style=" font-family:'Courier New'; font-size:small;">MAPIFolder, mynewfolder<br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">myNamespace = app.GetNamespace(</span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;MAPI&quot;</span><span style=" font-family:'Courier New'; font-size:small;">)<br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">myfolder = myNamespace.GetDefaultFolder(olFolderInbox)<br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Set myfolder = _<br />        '    app.ActiveExplorer.CurrentFolder.Folders</span><span style=" font-family:'Courier New'; font-size:small;"><br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">mynewfolder = myfolder.Folders.Add(</span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;My Contacts&quot;</span><span style=" font-family:'Courier New'; font-size:small;">)<br />        <br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Set </span><span style=" font-family:'Courier New'; font-size:small;">itm = app.CreateItem(olMailItem) </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Добавляем письмо</span><span style=" font-family:'Courier New'; font-size:small;"><br />        itm.Subject = Me.Subject  </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Тема письма</span><span style=" font-family:'Courier New'; font-size:small;"><br />        itm.Body = Me.Body </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Текст письма</span><span style=" font-family:'Courier New'; font-size:small;"><br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">If </span><span style=" font-family:'Courier New'; font-size:small;">myFile &lt;&gt; </span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;&quot;</span><span style=" font-family:'Courier New'; font-size:small;"> </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Then </span><span style=" font-family:'Courier New'; font-size:small;">itm.Attachments.Add myFile </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Прикрепляем файл</span><span style=" font-family:'Courier New'; font-size:small;"><br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">For </span><span style=" font-family:'Courier New'; font-size:small;">i = 0 </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">To </span><span style=" font-family:'Courier New'; font-size:small;">rst.RecordCount - 1 </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Просматриваем адреса</span><span style=" font-family:'Courier New'; font-size:small;"><br />            </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">If </span><span style=" font-family:'Courier New'; font-size:small;">rst!Вкл = </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">True Then </span><span style=" font-family:'Courier New'; font-size:small;">_<br />                itm.Recipients.Add rst!Email </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Добавляем новый адрес</span><span style=" font-family:'Courier New'; font-size:small;"><br />            rst.MoveNext </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Следующий адрес</span><span style=" font-family:'Courier New'; font-size:small;"><br />        </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Next</span><span style=" font-family:'Courier New'; font-size:small;"><br />        itm.Send </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Отсылаем письмо</span><span style=" font-family:'Courier New'; font-size:small;"><br />        app.Quit </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Закрываем Outlook</span><span style=" font-family:'Courier New'; font-size:small;"><br />        MsgBox </span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;Письмо успешно отправлено!&quot;</span><span style=" font-family:'Courier New'; font-size:small;">, vbExclamation, </span><span style=" font-family:'Courier New'; font-size:small; color:#660000;">&quot;Почта&quot;</span><span style=" font-family:'Courier New'; font-size:small;"><br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">End If</span><span style=" font-family:'Courier New'; font-size:small;"><br />    rst.Close </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Закрываем запрос</span><span style=" font-family:'Courier New'; font-size:small;"><br />    </span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">Exit Sub</span><span style=" font-family:'Courier New'; font-size:small;"><br />999:<br />    MsgBox Err.Description  </span><span style=" font-family:'Courier New'; font-size:small; color:#007700;">'Ошибка</span><span style=" font-family:'Courier New'; font-size:small;"><br />    Err.Clear<br />    app.Quit<br /></span><span style=" font-family:'Courier New'; font-size:small; color:#0000aa;">End Sub</span></p></body></html>